package com.base.cn.platform.os.controller.web.subject;

import com.base.cn.platform.os.common.WebBaseController;
import com.base.cn.platform.os.common.utils.DataUtil;
import com.base.cn.platform.os.common.utils.result.ResultUtil;
import com.base.cn.platform.os.service.manage.subject.SubjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 前台专业接口
 *
 * @author s.li
 * @create 2018-05-22-19:30
 */
@Controller
@RequestMapping("/web/subject")
public class WebSubjectController extends WebBaseController {

    @Autowired
    private SubjectService subjectService;

    /**
     * 查询专业数据
     * @return Map<String,Object>
     */
    @RequestMapping("/ajax/findLayeredSubjectList")
    @ResponseBody
    public Map<String,Object> findLayeredSubjectList(){
        Map<String,Object> params = new HashMap<>();
        params.put("status",1);//查询状态正常的
        Map<String,List<Map<String,Object>>> subjectMapList = subjectService.findSubjectListMap(params);
        return ResultUtil.SUCCESS("专业获取成功",subjectMapList);
    }


    /**
     * 专业定制搜索专业
     * @param model
     * @param parentId
     * @return
     */
    @RequestMapping("/ajax/loginCustomized")
    public String loginCustomized(Model model,@RequestParam("parentId") BigDecimal parentId) {
        Map<String, Object> condition = new HashMap<>(2);
        condition.put("status", 1);
        condition.put("parentId", parentId);
        List<Map<String, Object>> subjectList = subjectService.findSubjectList(condition);
        model.addAttribute("subjectList", subjectList);
        Map<String, Object> parent =new HashMap<>();
        if (DataUtil.idIsNotNull(parentId)) {
            parent= subjectService.findSubjectById(parentId);
        }
        model.addAttribute("parent", parent);
        return resultPage("/subject/customized/login-customized");
    }

}
